Type.registerNamespace('ModWatch');

ModWatch.ListBoxModWatcherBehavior = function(element) { 
    ModWatch.ListBoxModWatcherBehavior.initializeBase(this, [element]);

    this._valuesToCompare = null;
}

ModWatch.ListBoxModWatcherBehavior.prototype = {

	get_valuesToCompare : function()
	{
		return this._valuesToCompare;
	},

	set_valuesToCompare : function(value)
	{
		this._valuesToCompare = value;
	},

	hasChanged : function()
	{
		var i = 0;
		var listBox = this.get_element();
		var currSelections = new Array();

		for (var i = 0; i < listBox.options.length; i++)
		{
			if (listBox.options[i].selected)
				Array.add(currSelections, listBox.options[i].value);
		}

		if (!this._isListSubset(this._valuesToCompare, currSelections))
		{
			return true;
		}
		if (!this._isListSubset(currSelections, this._valuesToCompare))
		{
			return true;
		}

		return false;
	},
	
	_isListSubset : function(superset, subset) {
		var isSubset = true;
		
		var check = function(element, index, array)
		{
			if (!Array.contains(superset, element))
				isSubset = false;
		}
		
		Array.forEach(subset, check, null);
		
		return isSubset;
	}

}

ModWatch.ListBoxModWatcherBehavior.registerClass('ModWatch.ListBoxModWatcherBehavior', ModWatch.ModWatcherBehaviorBase);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
